package com.hrt.web.member.dao.impl;


import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.hrt.base.BaseDaoImpl;
import com.hrt.bean.HRTMember;
import com.hrt.web.member.dao.HRTMemberDao;


@Repository
public class HRTMemberDaoImpl extends BaseDaoImpl<HRTMember> implements HRTMemberDao {
	@Override
	public HRTMember checkHRTMemberOfUnamePwd(final String uname, final String pwd) {
		HRTMember hu = null;
		Session session = getSession();
		System.out.println("aaaaa====="+uname);
		System.out.println("bbbbb====="+pwd);
		if (pwd != null) {
			System.out.println("bbbb");
			hu = (HRTMember) session
					.createQuery(
							"FROM HRTMember h where h.mail=? and h.password=?")
					.setString(0, uname).setString(1, pwd).uniqueResult();
		} else {
			List list=this.getHibernateTemplate().find("select h from HRTMember h where h.mail='"+uname+"'");
			System.out.println(list==null);
			//.setString("mail", uname).list();
			if(list!=null && list.size()>0){
			hu = (HRTMember) list.get(0);
			}
		}
		return hu;
	}
	@Override
	public void addHRTMember(HRTMember hu) {
		getSession().save(hu);
		getSession().flush();
	}
	@Override
	public void updateHRTMemberMailCheck(HRTMember hu) {
		getSession().update(hu);
		getSession().flush();
	}
	@Override
	public HRTMember queryByName(String name) {
		String sql = "from HRTMember a where a.mbrName = '"+name+"'";
		return (HRTMember) getHibernateTemplate().find(sql).get(0);
	}
}
